package com.medical.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.medical.mapper.DeptScoreMapper;
import com.medical.model.entity.DeptScore;
import com.medical.service.DeptScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @author TISNIW
 * @version 1.0
 * @desc
 */
@Service
public class DeptScoreServiceImpl extends ServiceImpl<DeptScoreMapper, DeptScore> implements DeptScoreService {
    @Autowired
    private DeptScoreMapper deptScoreMapper;
    @Override
    public DeptScore getByDeptId(Long deptId) {
        return deptScoreMapper.getByDeptId(deptId);
    }


    public DeptScore saveScore(Long deptId, DeptScore deptScore) {
        // 设置 deptId 到实体类中
        deptScore.setDeptId(deptId);

        // 查询是否已有该部门的评分记录
        DeptScore existingScore = deptScoreMapper.selectByDeptId(deptId);

        if (existingScore != null) {
            // 存在记录，执行更新
            deptScore.setId(existingScore.getId());
            deptScoreMapper.updateById(deptScore);
            return deptScore;
        } else {
            // 不存在记录，执行新增
            deptScoreMapper.insert(deptScore);
            return deptScore;
        }
    }
}